package com.example.demo.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author xzy
 * @date 2020-11-08 14:25
 * 说明：银行账号信息表（bank_account）对应的实体类
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "bank_account")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BankAccountEntity implements Serializable {

    private static final long serialVersionUID = -3885864036334644489L;

    @Id
    @GenericGenerator(name = "genericGenerator", strategy = "uuid")
    @GeneratedValue(generator = "genericGenerator")
    private String id;

    /**
     * 账号
     */
    private String account;

    /**
     * 持有人姓名
     */
    private String customerName;

    /**
     * 余额
     */
    private BigDecimal balance;

    @CreatedBy
    private String createBy;

    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createDate;

    @LastModifiedBy
    private String updateBy;

    @LastModifiedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateDate;

    /**
     * 逻辑删除标识（0：未删除 1：已删除）
     */
    private String deleteFlag;

    {
        this.balance = BigDecimal.ZERO;
        this.deleteFlag = "0";
    }

    public BankAccountEntity(String account, String customerName, BigDecimal balance) {
        this.account = account;
        this.customerName = customerName;
        this.balance = balance;
    }
}
